package com.service;

import com.bean.Book;
import com.dao.BookDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author hecn
 * @version 1.0
 * @date 2020/8/2 0002 0:54
 */
public class BorrowBookServlet extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");

        String book_name = req.getParameter("book_name");
        BookDao bookDao = new BookDao();
        Book book = bookDao.retandborBook(book_name);
        int sum = bookDao.updateBook(book, -1);
        req.setAttribute("sum", sum);

        req.getRequestDispatcher("borrowSuccess.jsp").forward(req, resp);


    }
}
